/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Technical;

import domain.GameGrid;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.InputStreamReader;

public class GridReader {

    public GridReader() {
    }

    public int[][] ReadGrid(String fileName) {
        String line;
        int[][] gameGrid = new int[8][8];
        int j = 0;

        try {
            FileInputStream fstream = new FileInputStream(fileName);
            DataInputStream in = new DataInputStream(fstream);
            BufferedReader br = new BufferedReader(new InputStreamReader(in));

            while ((line = br.readLine()) != null) {
                for(int i = 0; i < 8; i++)
                {
                    switch(line.charAt(i))
                    {
                        case 48:
                            gameGrid[j][i] = 0;
                            break;
                        case 49:
                            gameGrid[j][i] = 1;
                            break;
                        case 50:
                            gameGrid[j][i] = 2;
                            break;                                    
                    }
                }
                j++;
            }
            in.close();
        } catch (Exception e) {
            e.toString();
        }

        return gameGrid;
    }
}